﻿function ClientAddResource() {
    ResourceTypeIndex=document.getElementById("drpSelectResourceType").selectedIndex;
    ResourceTypeId=document.getElementById("drpSelectResourceType").options[ResourceTypeIndex].value;
    Url = Portal.OfficeMan.Resource.GetAddUrl(ResourceTypeId).value;
    //window.showModalDialog(Url, null, 'dialogHeight: 600px; dialogWidth: 800px; dialogTop: 10px; dialogLeft: 150px; edge: Raised; center: Yes; help: No; scroll: Yes; status: Yes;');
    window.open(Url, '_self');
    ClientReading();
}

function ClientSaveAddResource(ResourceTypeId) {
    ResourceCode = document.getElementById("txtResourceCode").value;
    ResourceName = document.getElementById("txtResourceName").value;

    RetValue = Portal.OfficeMan.AddResource.ServerSideAddResource(ResourceCode,ResourceName,ResourceTypeId).value;
    if(RetValue.indexOf("ERROR")!=-1)
    {
        alert(RetValue);
        return;
    }
    alert(RetValue);
    document.getElementById("txtResourceCode").value = "";
    document.getElementById("txtResourceName").value = "";
    document.getElementById("txtResourceCode").focus();
    //window.close();
}

function ClientUpdateResource(ResourceId) {
    Url = Portal.OfficeMan.Resource.GetUpdateUrl(ResourceId).value;
    //window.showModalDialog(Url, null, 'dialogHeight: 600px; dialogWidth: 800px; dialogTop: 10px; dialogLeft: 150px; edge: Raised; center: Yes; help: No; scroll: Yes; status: Yes;');
    window.open(Url, '_self');
    //ClientReading();
}

function ClientDeleteResource(ResourceId)
{
    Msg=Portal.OfficeMan.Resource.GetConfirmDeleteMsg().value;
    if(confirm(Msg)==false)return;
    RetValue = Portal.OfficeMan.Resource.ServerSideDeleteResource(ResourceId).value;
    if(RetValue.indexOf("ERROR")!=-1)
    {
        alert(RetValue);
        return;
    }
    alert(RetValue);
    ClientReading();
}



function ShowClientUpdateUrlForm(ResourceId)
{
    Url = Portal.OfficeMan.Resource.GetUpdateUrl(ResourceId).value;
    if(Url.indexOf("ERROR")!=-1)
    {
        alert(Url);
        return;
    }
    //window.showModalDialog(Url, null, 'dialogHeight: 600px; dialogWidth: 800px; dialogTop: 10px; dialogLeft: 150px; edge: Raised; center: Yes; help: No; scroll: Yes; status: Yes;');
    window.open(Url, "_self");
}


function ClientSaveUpdateResource(ResourceId)
{
    ResourceCode = document.getElementById("txtResourceCode").value;
    ResourceName = document.getElementById("txtResourceName").value;

    RetValue = Portal.OfficeMan.UpdateResource.ServerSideUpdateResource(ResourceId,ResourceCode, ResourceName).value;
    if(RetValue.indexOf("ERROR")!=-1)
    {
        alert(RetValue);
        return;
    }
    alert(RetValue);
    //window.close();
    window.open("default.aspx?WebPartId=Resource", "_self");
}

function ClientReading() {
   document.getElementById("divProcessing").innerHTML = Portal.OfficeMan.Resource.GetProcessingText().value;
   setTimeout("RealClientReading()",10);
}

function RealClientReading() {
    ResourceTypeIndex=document.getElementById("drpSelectResourceType").selectedIndex;
    ResourceTypeId=document.getElementById("drpSelectResourceType").options[ResourceTypeIndex].value;
    rValue = Portal.OfficeMan.Resource.GetResource(ResourceTypeId).value;
    document.getElementById("divResourceContent").innerHTML = rValue;
    document.getElementById("divProcessing").innerHTML = "";
}
